<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
    <div >
        <div class="layui-tab">
            <ul class="layui-tab-title">
            <li class="layui-this"> 
                <i class="layui-icon">基础资料设置</i>
            </li>
            <li  id="exampleis" style="display: none;">
                <i class="layui-icon">手机号登录设置</i>
            </li>
            </ul>
            <div class="layui-tab-content" >
            <div class="layui-tab-item layui-show layui-form layuimini-form"    lay-filter="example" >
                    <input type="hidden" name="id" id="id" value="">
                    <div class="layui-form-item">
                        <label class="layui-form-label required">昵称</label>
                        <div class="layui-input-block">
                            <input type="text" name="username" id="username" lay-verify="required" lay-reqtext="昵称" placeholder="昵称" value="" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label required">角色</label>
                        <div class="layui-input-block">
                            <select name="level_id" id="level_id">
                            </select>
                        </div>
                    </div>
                        
                    <div class="layui-form-item">
                        <label class="layui-form-label required">登录账号</label>
                        <div class="layui-input-block">
                            <input type="text" name="appname" lay-verify="required" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label required">密码</label>
                        <div class="layui-input-block">
                            <input type="password" name="usernewpwd"  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label required">性别</label>
                        <div class="layui-input-block">
                            <input type="radio" name="sex" value="1" title="男" checked="">
                            <input type="radio" name="sex" value="2" title="女">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label required">状态</label>
                        <div class="layui-input-block">
                            <input type="radio" name="status" value="1" title="正常" checked="">
                            <input type="radio" name="status" value="2" title="禁闭中">
                            <input type="radio" name="status" value="3" title="禁用">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">头像</label>
                        <input type="hidden" name="small_pic" id="small_pic" value="">
                        <div class="layui-input-block">
                            <div class="layui-upload">
                                <button type="button" class="layui-btn layui-btn-primary" id="cateBtn">
                                    <i class="icon icon-upload3"></i>点击上传</button>
                                <div class="layui-upload-list">
                                    <img class="layui-upload-img" style="width: 200px;height: 100px;" id="cateImage" src="">
                                    <p id="demoText"></p>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
                        </div>
                    </div>
            </div>
            <div class="layui-tab-item layui-form layuimini-form"  lay-filter="examplemobile">
                    <div class="layui-form-item">
                        <label class="layui-form-label">手机号</label>
                        <div class="layui-input-block">
                            <input type="hidden" name="user_id" id="user_id" value="">
                            <input type="hidden" name="mobile_id" id="mobile_id" value="">
                            <input type="number" name="mobile" id="mobile"   maxlength="11"  value="" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">国家代码</label>
                        <div class="layui-input-block">
                            <input type="text" name="country_code" id="country_code"  class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtnis">确认保存</button>
                        </div>
                    </div>
            </div>
            </div>
        </div>
    </div>
    <script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <script src="../../js/lay-config.js" charset="utf-8"></script>
<script>
   layui.use(['form','upload','http'], function () {
        var form = layui.form,
            layer = layui.layer,
            uploadInst = layui.upload,
            http  = layui.http,
            apiurl =http.api,
            $ = layui.$;


        http.verifyToken();
        getUserlevelList();
        var id  = http.getQueryString('id');
        if(id){
            getUserInfo(id);
        }
        //监听提交
        form.on('submit(saveBtnis)', function (data) {
            var da ={"user_id":data.field.user_id,"id":data.field.mobile_id,"mobile":data.field.mobile,"country_code":data.field.country_code};
            http.httpajax("Personal/userMobileUpAddata",da,"POST",function(res) {
                if(res.code === '0000'){
                    layer.msg(res.msg,{time:1000,icon:1},function(){
                        // 关闭弹出层
                        layer.close();
                        window.parent.location.reload();//刷新父页面
                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(iframeIndex);
                    });
                }else{
                    layer.msg(res.msg,{time:1000,icon:2});
                }
            });
        });

        form.on('submit(saveBtn)', function (data) {
            http.httpajax("Personal/userUpAddata", data.field,"POST",function(res) {
                if(res.code === '0000'){
                    layer.msg(res.msg,{time:1000,icon:1},function(){
                        // 关闭弹出层
                        layer.close();
                        window.parent.location.reload();//刷新父页面
                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(iframeIndex);
                    });
                }else{
                    layer.msg(res.msg,{time:1000,icon:2});
                }
            });
        });
        function getUserlevelList(){
            http.httpajax("Personal/userlevelList",{},"POST",function(res) {
                if(res.code == '0000'){
                    for(var i =0;i<res.data.length;i++){
                        $("#level_id").append("<option value=\""+res.data[i].id+"\">"+res.data[i].name+"</option>");
                    }
                     //重新渲染
                     layui.form.render("select");
                }else{ 
                    layer.msg(res.msg,{time:1000,icon:2});
                } 
            });
        }

        function getUserInfo(){
            http.httpajax("Personal/userList",{'id':id},"POST",function(res) {
                if(res.code == '0000'){
                    form.render();
                    form.val('example', res.data)
                    form.val('examplemobile', res.data)
                    $('#cateImage').attr('src',res.data.small_pic);
                    $('#user_id').val(res.data.id);
                    $("#exampleis").show();
                }else{
                    layer.msg(res.msg,{time:1000,icon:2});
                }
            });
        }
        
        http.uplode("cateBtn",function(res) {
            if(res.code==200){
                $('#small_pic').val(res.data);
                $('#cateImage').attr('src',res.data);
                layer.msg("上传成功",{offset:['200px','450px'],icon:6});
            }else{
                //如果上传失败
                return layer.msg('上传失败');
            }
        });
    });
    
</script>
</body>
</html>